Skip to content

Add specialized pair construction API #3990

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Conversation

nikic
Copy link
Member

@nikic nikic commented Mar 26, 2019

Add a zend_new_pair() function for creating a pair array. This cuts down instructions for subpat population from 67k to 52k on a remex-html benchmark.

@KalleZ KalleZ requested a review from dstogov March 26, 2019 09:25
ZEND_API HashTable* ZEND_FASTCALL zend_new_pair(zval *val1, zval *val2)
{
Bucket *p;
HashTable *ht = emalloc(sizeof(HashTable));
Copy link
Member

@krakjoe krakjoe Mar 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How aggressive do you want to be here ?

Might it be possible to make alloc for ht+buckets one allocation, might it also be possible to omit hash_init_int, and write a hash_init_pair (in place of real_init_packed) ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would love to combine those allocations, but I don't think it's possible. The rest of the hash API assumes that these are separate allocations, and in the end the pair is still a normal array and can be used as such.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a shame ... what about a specialized init ? among other things, init_int sets flags and then immediately real_init_packed sets them otherwise ? it looks like you could avoid the persistent branch in real_init too ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would hope that all of this will get optimized because these functions are always_inline, but I'll have to check assembly to be sure.

@cscott
Copy link
Contributor

cscott commented Mar 29, 2019

On latest version of remex-html benchmark (with fixes to ensure the character reference regexp doesn't go through the slow path in zend_hash_find):

Callgrind cycles spent in php_pcre_match_impl:
Before: 450,762,191
After: 430,904,330

So a nice 4.4% speed improvement with what seems like not too much extra code complexity.

The populate_subpat_array function accounts for:
Before: 199,474,023
After: 179,661,545

So still a substantial fraction of the overall pcre match time. @nikic had the idea of returning a lazy object as $matches to reduce this overhead further, which seems worthwhile.

@nikic
Copy link
Member Author

nikic commented Jun 7, 2019

@dstogov Is adding this kind of API okay? It's a small optimization for pcre.

@dstogov
Copy link
Member

dstogov commented Jun 7, 2019

looks fine

@php-pulls php-pulls closed this in 51fb8dc Jun 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants